<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Coin extends Model
{
    use HasDateTimeFormatter;
    use SoftDeletes;

    protected $table = 'coin';

    protected $guarded = ['id'];

    const STATUS_OPEN = 1;
    const STATUS_ClOSE = 0;
    const STATUS = [
        self::STATUS_OPEN => '开启',
        self::STATUS_ClOSE => '关闭',
    ];

    const IS_NEW_USER_ONLY_YES = 1;
    const IS_NEW_USER_ONLY_NO = 0;
    const IS_NEW_USER_ONLY = [
        self::IS_NEW_USER_ONLY_YES => '是',
        self::IS_NEW_USER_ONLY_NO => '否',
    ];

    const IS_UNLOCK_YES = 1;
    const IS_UNLOCK_NO = 0;
    const IS_UNLOCK = [
        self::IS_UNLOCK_YES => '已解锁',
        self::IS_UNLOCK_NO => '未解锁',
    ];

    const IS_TRUE_YES = 1;
    const IS_TRUE_NO = 0;
    const IS_TRUE = [
        self::IS_TRUE_YES => '真',
        self::IS_TRUE_NO => '假',
    ];

    const TYPE_JIN = 1;
    const TYPE_YIN = 2;
    const TYPE_TONG = 3;
    const TYPE_ZM = 4;
    const TYPE_LW = 5;
    const TYPE = [
        self::TYPE_JIN => '金币',
        self::TYPE_YIN => '银币',
        self::TYPE_TONG => '铜币',
        self::TYPE_ZM => '字母',
        self::TYPE_LW => '礼物',
    ];

    const TYPE_ZM_STR = 'QUXUN'; // 字母全部大写
    const TYPE_ZM_SET = [
        'Q' => 'Q',
        'U' => 'U',
        'X' => 'X',
        'N' => 'N',
    ];

    const NUMBER = [
        1 => '10',
        2 => '5',
        3 => '5',
        4 => '2',
        5 => '2',
        6 => '2',
        7 => '2',
        8 => '0.7',
        9 => '0.7',
        10 => '0.7',
        11 => '0.7',
        12 => '0.7',
        13 => '0.7',
        14 => '0.7',
        15 => '0.7',
    ];

    const NUMBER_AMOUNT = 328; // 金币价格（已废弃）

    public function clue()
    {
        return $this->hasMany('App\Models\CoinClue', 'coin_id');
    }

    public function user_clue()
    {
        return $this->hasMany('App\Models\UserCoinClue', 'coin_id');
    }

    public function user_coin()
    {
        return $this->hasMany('App\Models\UserCoin', 'coin_id');
    }

    public function getIconAttribute($value)
    {
        return ($this->type == self::TYPE_LW && $value) ? trim(config('filesystems.disks.aliyun.domain'), '/') . '/' . $value : $value;
    }
}
